package com.example.testproject.adapter

import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.testproject.R
import kotlinx.android.synthetic.main.text_layout.view.*

/**
 *
 * @ClassName: RvAnalysisAdapter
 * @Author: android 超级兵
 * @CreateDate: 11/3/21$ 10:27 AM$
 * TODO
 */
class RvAnalysisAdapter(val list: List<String>) :
    RecyclerView.Adapter<RvAnalysisAdapter.ViewHolder>() {

    override fun getItemCount(): Int = let {
//        Log.i("szjRecyclerView", "getItemCount :position:${list.size}")
        list.size
    }

//    override fun getItemViewType(position: Int): Int {
//        return position % 2
//    }

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = let {
        Log.i("szjRecyclerView", "onCreateViewHolder")
        ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.text_layout, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        if (holder.itemViewType == 0) {
            holder.itemView.textView.text = list[position]
            holder.itemView.textView.setBackgroundColor(Color.GRAY)
        } else if (holder.itemViewType == 1) {
            holder.itemView.textView.setBackgroundColor(Color.RED)
        }
        Log.i(
            "szjRecyclerView",
            "onBindViewHolder :position:${position}== itemViewType:${holder.itemViewType}"
        )
    }

}